package com.ts.proj.json;

import com.ts.base.controller.BaseController;
import com.ts.common.constant.InsUpdDelFlagConstant;
import com.ts.common.constant.SystemButtonTableColumnConstant;
import com.ts.common.constant.SystemUserTableColumnConstant;
import com.ts.proj.entity.SystemButtonEntity;
import com.ts.proj.entity.SystemMenuEntity;
import com.ts.proj.service.SystemButtonService;
import com.ts.proj.service.SystemMenuService;
import com.ts.util.DateUtil;
import com.ts.util.PageData;
import com.ts.util.RightsHelper;
import com.ts.util.TreeMenuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@Slf4j
public class SystemButtonJson extends BaseController {


    @Autowired
    private SystemButtonService systemButtonService;

    @RequestMapping("/btn-save/{id}/{menuId}")
    public Map<String,Object> menuSave(@PathVariable("id") String id,@PathVariable("menuId") String menuId){
        PageData pageData = this.getPageData();
        SystemButtonEntity systemButtonEntity = systemButtonService.findById(Integer.valueOf(id));
        if(null!=pageData.get("btn_name")&&!"".equals(pageData.get("btn_name").toString())){
            systemButtonEntity.setButtonName(pageData.getString("btn_name"));
        }
        if(null!=pageData.get("btn_remark")&&!"".equals(pageData.get("btn_remark").toString())){
            systemButtonEntity.setButtonRemark(pageData.getString("btn_remark"));
        }
        if(null!=pageData.get("btn_icon")&&!"".equals(pageData.get("btn_icon").toString())){
            systemButtonEntity.setIconCls(pageData.getString("btn_icon"));
        }
        if(null!=pageData.get("btn_id")&&!"".equals(pageData.get("btn_id").toString())){
            systemButtonEntity.setButtonId(pageData.getString("btn_id"));
        }
        if(null!=menuId&&!"".equals(menuId)&&!"-1".equals(menuId)){
            systemButtonEntity.setMenuID(Integer.valueOf(menuId));
        }
        if(null!=pageData.get("deleteFlag")&&"Y".equals(pageData.get("deleteFlag").toString())){
            systemButtonEntity.setDeleteFlag(InsUpdDelFlagConstant.DELETE_FLAG_Y);
        }
        SystemButtonEntity save = systemButtonService.save(systemButtonEntity);
        Map<String, Object> map = new HashMap<>();
        map.put("result", "success");
        map.put("parentId", save.getMenuID() + 1000);
        return map;
    }
}
